/*
 *  RessourcesManager.cpp
 *  Rempart
 *
 *  Created by julien BONACHERA on 29/05/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "RessourcesManager.h"

RessourcesManager* RessourcesManager::instance(0);
sf::Image* RessourcesManager::groundSurface(0);
sf::Image* RessourcesManager::surfaceMouseOver(0);
sf::Image* RessourcesManager::surfaceWall(0);
sf::Image* RessourcesManager::surfaceWater(0);
sf::Image* RessourcesManager::surfaceTower(0);
sf::Image* RessourcesManager::surfaceTowerSecure(0);
sf::Image* RessourcesManager::surfaceBodyCanon(0);
sf::Image* RessourcesManager::surfaceTubeCanon(0);
sf::Image* RessourcesManager::secureGroundSurface(0);
sf::Image* RessourcesManager::collisionMouseOverSurface(0);
sf::Image* RessourcesManager::surfaceBullet(0);
sf::Image* RessourcesManager::surfaceBulletBoat(0);
sf::Image* RessourcesManager::surfaceLooseSplashScreen(0);
sf::Image* RessourcesManager::surfaceCursor(0);
sf::Image* RessourcesManager::surfaceBoat(0);

sf::Image* RessourcesManager::stage1Screen(0);
sf::Image* RessourcesManager::stage2Screen(0);
sf::Image* RessourcesManager::stage3Screen(0);

RessourcesManager::RessourcesManager(){
}
RessourcesManager::~RessourcesManager(){
	delete groundSurface;
	delete secureGroundSurface;
	delete surfaceMouseOver;
	delete collisionMouseOverSurface;
	delete surfaceWall;
	delete surfaceWater;
	delete surfaceTower;
	delete surfaceTowerSecure;
	delete surfaceBodyCanon;	
	delete surfaceTubeCanon;	
	delete surfaceBullet;
	delete surfaceBulletBoat;
	delete surfaceLooseSplashScreen;
	delete surfaceCursor;
	delete stage1Screen;
	delete stage2Screen;
	delete stage3Screen;
	
	printf("RessourcesManager supprimé.\n");
	
	
}

RessourcesManager * RessourcesManager::getInstance() {
	
	if (instance == 0) {
		instance = new RessourcesManager();
	}
	return instance;
}

sf::Image* RessourcesManager::getCursorSurface(){	
	if(surfaceCursor == 0){
		surfaceCursor = new sf::Image();
		if(!surfaceCursor->LoadFromFile(SPRITE_ELEM_CURSOR)){
			throw std::exception();
		}
		surfaceCursor->SetSmooth(false);
	}
	return surfaceCursor;
}

sf::Image* RessourcesManager::getDefaultGroundSurface(){	
	if(groundSurface == 0){
		groundSurface = new sf::Image();
		if(!groundSurface->LoadFromFile(SPRITE_ELEM_GROUND)){
			throw std::exception();
		}
		groundSurface->SetSmooth(false);
	}
	return groundSurface;
}

sf::Image* RessourcesManager::getSecureGroundSurface(){	
	if(secureGroundSurface == 0){
		secureGroundSurface = new sf::Image();
		if(!secureGroundSurface->LoadFromFile(SPRITE_ELEM_GROUND_SEC)){
			throw std::exception();
		}
		secureGroundSurface->SetSmooth(false);
	}
	return secureGroundSurface;
}



sf::Image* RessourcesManager::getDefaultMouseOverSurface(){	
	if(surfaceMouseOver == 0){
		surfaceMouseOver = new sf::Image();
		if(!surfaceMouseOver->LoadFromFile(SPRITE_ELEM_GROUND_MOUSEOVER)){
			throw std::exception();
		}
		surfaceMouseOver->SetSmooth(false);
	}
	return surfaceMouseOver;
}


sf::Image* RessourcesManager::getDefaultWallSurface(){
	if(surfaceWall == 0){
		surfaceWall = new sf::Image();
		if(!surfaceWall->LoadFromFile(SPRITE_ELEM_WALL)){
			throw std::exception();
		}
		surfaceWall->SetSmooth(false);
	}
	return surfaceWall;
}

sf::Image* RessourcesManager::getDefaultTowerSurface(){
	if(surfaceTower == 0){
		surfaceTower = new sf::Image();
		if(!surfaceTower->LoadFromFile(SPRITE_ELEM_TOWER)){
			throw std::exception();
		}
		surfaceTower->SetSmooth(false);
	}
	return surfaceTower;
}

sf::Image* RessourcesManager::getSecureTowerSurface(){
	if(surfaceTowerSecure == 0){
		surfaceTowerSecure = new sf::Image();
		if(!surfaceTowerSecure->LoadFromFile(SPRITE_ELEM_TOWER_SECURE)){
			throw std::exception();
		}
		surfaceTowerSecure->SetSmooth(false);
	}
	return surfaceTowerSecure;
}

sf::Image* RessourcesManager::getDefaultBodyCanonSurface(){
	if(surfaceBodyCanon == 0){
		surfaceBodyCanon = new sf::Image();
		if(!surfaceBodyCanon->LoadFromFile(SPRITE_ELEM_CANON_BODY)){
			throw std::exception();
		}
		surfaceBodyCanon->SetSmooth(false);
	}
	return surfaceBodyCanon;
}
sf::Image* RessourcesManager::getDefaultTubeCanonSurface(){
	if(surfaceTubeCanon == 0){
		surfaceTubeCanon = new sf::Image();
		if(!surfaceTubeCanon->LoadFromFile(SPRITE_ELEM_CANON_TUBE)){
			throw std::exception();
		}
		surfaceTubeCanon->SetSmooth(false);
	}
	return surfaceTubeCanon;
}


sf::Image* RessourcesManager::getCollisionMouseOverSurface(){
	if(collisionMouseOverSurface == 0){
		collisionMouseOverSurface = new sf::Image();
		if(!collisionMouseOverSurface->LoadFromFile(SPRITE_ELEM_COLLISION_MOUSEOVER)){
			throw std::exception();
		}
		collisionMouseOverSurface->SetSmooth(false);
	}
	return collisionMouseOverSurface;
}


sf::Image* RessourcesManager::getDefaultWaterSurface(){
	if(surfaceWater == 0){
		surfaceWater = new sf::Image();
		if(!surfaceWater->LoadFromFile(SPRITE_ELEM_WATER)){
			throw std::exception();
		}
		surfaceWater->SetSmooth(false);
	}
	return surfaceWater;
	
}

sf::Image* RessourcesManager::getDefaultBulletSurface(){
	if(surfaceBullet == 0){
		surfaceBullet = new sf::Image();
		if(!surfaceBullet->LoadFromFile(SPRITE_ELEM_BULLET)){
			throw std::exception();
		}
		surfaceBullet->SetSmooth(false);
	}
	return surfaceBullet;
}

sf::Image* RessourcesManager::getBoatBulletSurface(){
	if(surfaceBulletBoat == 0){
		surfaceBulletBoat = new sf::Image();
		if(!surfaceBulletBoat->LoadFromFile(SPRITE_ELEM_BULLET_BOAT)){
			throw std::exception();
		}
		surfaceBulletBoat->SetSmooth(false);
	}
	return surfaceBulletBoat;
}

sf::Image* RessourcesManager::getLooseSplashScreenSurface(){
	if(surfaceLooseSplashScreen == 0){
		surfaceLooseSplashScreen = new sf::Image();
		if(!surfaceLooseSplashScreen->LoadFromFile(LOOSE_SPLASH_SCREEN)){
			throw std::exception();
		}
		surfaceLooseSplashScreen->SetSmooth(false);
	}
	return surfaceLooseSplashScreen;
}


sf::Image* RessourcesManager::getDefaultBoatSurface(){
	if(surfaceBoat == 0){
		surfaceBoat = new sf::Image();
		if(!surfaceBoat->LoadFromFile(SPRITE_ELEM_BOAT)){
			throw std::exception();
		}
		surfaceBoat->SetSmooth(false);
	}
	return surfaceBoat;
}

sf::Image* RessourcesManager::getStage1Screen(){
	if(stage1Screen == 0){
		stage1Screen = new sf::Image();
		if(!stage1Screen->LoadFromFile(STAGE1_SCREEN)){
			throw std::exception();
		}
		stage1Screen->SetSmooth(false);
	}
	return stage1Screen;
}

sf::Image* RessourcesManager::getStage2Screen(){
	if(stage2Screen == 0){
		stage2Screen = new sf::Image();
		if(!stage2Screen->LoadFromFile(STAGE2_SCREEN)){
			throw std::exception();
		}
		stage2Screen->SetSmooth(false);
	}
	return stage2Screen;
}
sf::Image* RessourcesManager::getStage3Screen(){
	if(stage3Screen == 0){
		stage3Screen = new sf::Image();
		if(!stage3Screen->LoadFromFile(STAGE3_SCREEN)){
			throw std::exception();
		}
		stage3Screen->SetSmooth(false);
	}
	return stage3Screen;
}

sf::Image* RessourcesManager::getStageScreen(int stage){

	switch (stage) {
		case 1:
			return getStage1Screen();
			break;
		case 2:
			return getStage2Screen();
			break;
		case 3:
			return getStage3Screen();
			break;

		default:
			break;
	}

}